/*
 * Copyright (C) 2014 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.camera;

import rpg.RPG;
import rpg.gfx.Bitmap;

/**
 *
 * @author Rothens
 */
public class CELetterbox extends CinematicEffect {
    
    private static int LB_MAX_SIZE = 100; 
    
    private int length;
    private int currentTick = 0;
    private int inTime = 60;
    private int outTime = 60;
    
    public CELetterbox(int length){
        this.length = length;
    }
    

    @Override
    public boolean tick() {
        currentTick++;        
        return length <= currentTick;
    }

    @Override
    public Bitmap getBitmap(Bitmap toDrawOn) {
        if(currentTick > inTime && currentTick < length-outTime){
            toDrawOn.fill(0xff000000, 0, 0, RPG.WINDOW_WIDTH, LB_MAX_SIZE);
            toDrawOn.fill(0xff000000, 0, RPG.WINDOW_HEIGHT-LB_MAX_SIZE, RPG.WINDOW_WIDTH, RPG.WINDOW_HEIGHT);
        } else {
            double rate = 0;
            if(currentTick <= inTime){
                rate = (double)currentTick / (double)inTime;
            } else {
                rate = 1 - (double)(currentTick-(length-outTime))/outTime;
            }
            int h = (int) (rate * LB_MAX_SIZE);
            
            toDrawOn.fill(0xff000000,0,0,RPG.WINDOW_WIDTH, h);
            toDrawOn.fill(0xff000000, 0, RPG.WINDOW_HEIGHT-h, RPG.WINDOW_WIDTH, RPG.WINDOW_HEIGHT);
        }
        return toDrawOn;
    }
    
}
